package com.gitee.qdbp.general.marketing.biz.activity.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.able.result.ResultCode;
import com.gitee.qdbp.general.marketing.api.activity.model.ActivityCoreBean;
import com.gitee.qdbp.general.marketing.api.activity.models.ActivityCreateParams;
import com.gitee.qdbp.general.marketing.api.activity.service.IActivityManageService;
import com.gitee.qdbp.general.marketing.biz.activity.basic.ActivityCoreBasic;
import com.gitee.qdbp.tools.utils.VerifyTools;

/**
 * 活动管理处理类
 *
 * @author zhh
 * @version 181114
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public class ActivityManageService implements IActivityManageService {

    /** 日志对象 **/
    private static final Logger log = LoggerFactory.getLogger(ActivityManageService.class);

    /** 活动主DAO **/
    @Autowired
    private ActivityCoreBasic activityCoreBasic;

    public String createActivity(ActivityCreateParams params) {
        String msg = "Failed to create activity. ";

        if (VerifyTools.isBlank(params)) {
            log.error(msg + "params is null");
            throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED);
        }
        if (VerifyTools.isBlank(params.getActivityName())) {
            log.error(msg + "params is null: ActivityName");
            throw new ServiceException(ResultCode.PARAMETER_IS_REQUIRED);
        }

        ActivityCoreBean bean = params.to(ActivityCoreBean.class);
        activityCoreBasic.create(bean);

        // TODO 创建奖品
        // TODO 创建奖项

        return bean.getId();
    }
}
